package org.dtrd.modules.flup.entity.bean;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.flup.entity.po.DtrdEntRdFlupAppointmentRecord;
import org.dtrd.modules.patient.entity.po.DtrdEntRdPatient;

import java.util.Date;

/**
 * @author qr
 * @date 2021/12/16 16:52
 */
@ApiModel("患者随访信息")
@Data
@NoArgsConstructor
public class PatientFlupInfo {

    @ApiModelProperty("患者id")
    private Integer patientId;

    @ApiModelProperty("复诊预约记录id")
    private Integer flupId;

    @ApiModelProperty("复诊时间")
    private String flupDate;

    @ApiModelProperty("复诊时间段")
    private Integer flupTime;

    @ApiModelProperty("开始时间")
    private String startTime;

    @ApiModelProperty("结束时间")
    private String endTime;

    @ApiModelProperty("复诊模版")
    private Integer flupTemplateId;

    @ApiModelProperty("性别")
    private Integer sex;
    @ApiModelProperty("性别")
    private String sexText;

    @ApiModelProperty("名字")
    private String name;

    @ApiModelProperty("年龄")
    private String age;

    @ApiModelProperty("机构")
    private String organization;

    @ApiModelProperty("糖尿病类型")
    private String diabetesType;

    @ApiModelProperty("确诊时间")
    private String diabetesDate;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("头像")
    private String avatar;

    @ApiModelProperty("主诉")
    private String patientDesc;

    @ApiModelProperty("症状")
    private String symptom;

    public PatientFlupInfo(DtrdEntRdFlupAppointmentRecord po) {
        parseFromPo(po);
    }

    @SneakyThrows
    public PatientFlupInfo parseFromPo(DtrdEntRdFlupAppointmentRecord po) {
        flupId = po.getDataId();
        patientId = po.getPatientId();
        flupDate = DateUtils.formatDate(po.getFlupDate(), DateUtils.date_sdf.get().toPattern());
        flupTime = po.getFlupTime();
        Constant.FlupTime time = Constant.FlupTime.valueOf(po.getFlupTime());
        assert time != null;
        startTime = time.getStartTime();
        endTime = time.getEndTime();
        flupTemplateId = po.getFlupTemplateId();
        remark = po.getRemark();
        return this;
    }

    @SneakyThrows
    public PatientFlupInfo parseFromPo(DtrdEntRdPatient po) {
        this.setName(po.getPatientsName());
        // 性别
        Integer sex = po.getPatientsSex();
        this.setSex(sex);
        this.setSexText(Constant.Sex.valueOf(sex).getName());
        // 年龄
        if (po.getPatientsBirthday() != null) {
            this.setAge(DateUtil.ageOfNow(po.getPatientsBirthday()) + "岁");
        }
        Integer diabetisType = po.getPatientsDiabetisType();
        this.setDiabetesType(Constant.DiabetesType.valueOf(diabetisType).getName());
        // 确诊时间
        Date patientsConfirmedDate = po.getPatientsConfirmedDate();
        if (patientsConfirmedDate != null) {
            this.setDiabetesDate(DateUtils.formatDate(patientsConfirmedDate, DateUtils.date_sdf.get().toPattern()));
        }
        // 症状
        this.setSymptom(po.getPatientsSymptoms());
        // 头像
        this.avatar = po.getPatientsImg();
        this.patientDesc = po.getPatientsDescription();
        return this;
    }
}
